<template>
  <div>
   <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="用户" prop="user">
       <el-input type="text" v-model="ruleForm.user" autocomplete="off"></el-input>
     </el-form-item>
     <el-form-item label="密码" prop="pass">
       <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
     </el-form-item>
     <el-form-item label="确认密码" prop="checkPass">
       <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
     </el-form-item>
     <el-form-item label="邮箱" prop="email"
           :rules="[
           { required: true, message: '请输入邮箱地址', trigger: 'blur' },
           { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
         ]"
     >
    <el-input v-model="ruleForm.email"></el-input>
     </el-form-item>
     <el-form-item>
       <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
       <el-button @click="resetForm('ruleForm')">重置</el-button>
     </el-form-item>
     </el-form>
   </div>
   </template>
   <script>
     export default {
       data() {
         //年龄规则
         // var checkAge = (rule, value, callback) => {
         //   if (!value) {
         //     return callback(new Error('年龄不能为空'));
         //   }
         //   setTimeout(() => {
         //     if (!Number.isInteger(value)) {
         //       callback(new Error('请输入数字值'));
         //     } else {
         //       if (value < 18) {
         //         callback(new Error('必须年满18岁'));
         //       } else {
         //         callback();
         //       }
         //     }
         //   }, 1000);
         // };
         var validatePass = (rule, value, callback) => {
           if (value === '') {
             callback(new Error('请输入密码'));
           } else {
             if (this.ruleForm.checkPass !== '') {
               this.$refs.ruleForm.validateField('checkPass');
             }
             callback();
           }
         };
         var validatePass2 = (rule, value, callback) => {
           if (value === '') {
             callback(new Error('请再次输入密码'));
           } else if (value !== this.ruleForm.pass) {
             callback(new Error('两次输入密码不一致!'));
           } else {
             callback();
           }
         };

         var validateuser = (rule, value, callback) => {
           if (value === '') {
             callback(new Error('请输入用户'));
           }
            else {
             callback();
           }
         };
         return {
           ruleForm: {
             id:"",
             user:'',
             pass: '',
             checkPass: '',
             email: ''
           },

           rules: {
             user: [
               { validator: validateuser, trigger: 'blur' }
             ],
             pass: [
               { validator: validatePass, trigger: 'blur' }
             ],
             checkPass: [
               { validator: validatePass2, trigger: 'blur' }
             ],
            // 年龄规则
             // age: [
             //   { validator: checkAge, trigger: 'blur' }
             // ]
           }
         };
       },
       created() {
      
        if (this.$route.query.newmsg.user_id){
        this.ruleForm.id=this.$route.query.newmsg.user_id;
        this.ruleForm.user=this.$route.query.newmsg.user_name;
         this.ruleForm.pass="";
         this.ruleForm.checkPass="";

        this.ruleForm.email=this.$route.query.newmsg.user_eimll;
        }else{
          this.$router.push({path:'/user/page1'});
        }

        // this.ruleForm.fileurlto=this.$route.query.newmsg.new_imge;
        //this.ruleForm.dialogImageUrl
       // this.ruleForm.disabled=true;
        //console.log(this.ruleForm.fileurl);
         //console.log(this.$refs.upload.file.url);
        //this.ruleForm.title=this.$route.query.newmsg.new_time;

       },
       methods: {
         submitForm(formName) {
           this.$refs[formName].validate((valid) => {
             if (valid) {

             this.$axios.post(process.env.API_HOST+"/houtai/index/adminup",{ id:this.ruleForm.id,user_name:this.ruleForm.user,user_password:this.ruleForm.pass,user_eimll:this.ruleForm.email
                     }).then(res=>{
                       if(res.status===200){
                          //console.log("ss");
                          //console.log(res.data);
                           this.open3(res.data.msg);


                       }




                   }), res => {
             // 错误回调
                                console.log(res);



                          }






             } else {
               console.log('error submit!!');
               return false;
             }
           });
         },
         resetForm(formName) {
           this.$refs[formName].resetFields();
         }
         ,
         open3(msg) {
                this.$message({
                  message: msg,
                  type: 'warning'
                });
              },
       }
     }
   </script>

<style>
</style>
